<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>重复一个字符串</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="function.str-pad.html">« str_pad</a></li>
      <li style="float: right;"><a href="function.str-replace.html">str_replace »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="ref.strings.html">字符串 函数</a></li>
    <li>重复一个字符串</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="function.str-repeat" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">str_repeat</h1>
  <p class="verinfo">(PHP 4, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">str_repeat</span> &mdash; <span class="dc-title">重复一个字符串</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.str-repeat-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>str_repeat</strong></span>(<span class="methodparam"><span class="type">string</span> <code class="parameter">$string</code></span>, <span class="methodparam"><span class="type">int</span> <code class="parameter">$times</code></span>): <span class="type">string</span></div>

  <p class="para rdfs-comment">
   返回 <code class="parameter">string</code> 重复
   <code class="parameter">times</code> 次后的结果。
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.str-repeat-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt>
<code class="parameter">string</code></dt>

     <dd>

      <p class="para">
       待操作的字符串。
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">times</code></dt>

     <dd>

      <p class="para">
       <code class="parameter">string</code> 被重复的次数。
      </p>
      <p class="para">
       <code class="parameter">times</code> 必须大于等于 0。如果 <code class="parameter">times</code> 被设置为 0，函数返回空字符串。
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.str-repeat-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   返回重复后的字符串。
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.str-repeat-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-4826">
    <p><strong>示例 #1 <span class="function"><strong>str_repeat()</strong></span> 范例</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">echo&nbsp;</span><span style="color: #0000BB">str_repeat</span><span style="color: #007700">(</span><span style="color: #DD0000">"-="</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">10</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>以上例程会输出：</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
-=-=-=-=-=-=-=-=-=-=
</pre></div>
    </div>
   </div>   
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.str-repeat-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><a href="control-structures.for.html" class="link">for</a></li>
    <li class="member"><span class="function"><a href="function.str-pad.html" class="function" rel="rdfs-seeAlso">str_pad()</a> - 使用另一个字符串填充字符串为指定长度</span></li>
    <li class="member"><span class="function"><a href="function.substr-count.html" class="function" rel="rdfs-seeAlso">substr_count()</a> - 计算字串出现的次数</span></li>
   </ul>
  </p>
 </div>


</div></div></div></body></html>